package com.situ.day250113;

import org.junit.Test;

import java.util.Scanner;

public class MyTest1 {
    @Test
    public void test78() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = scanner.nextLine();
        char[] array = str.toCharArray();
        int letterCount = 0;
        int spaceCount = 0;
        int digitCount = 0;
        int otherCount = 0;
        for (int i = 0; i < array.length; i++) {
            if ((array[i] >= 'A' && array[i] <= 'Z') || (array[i] >= 'a' && array[i] <= 'z')) {
                letterCount++;
            } else if (array[i] == ' ') {
                spaceCount++;
            } else if (array[i] >= '0' && array[i] <= '9') {
                digitCount++;
            } else {
                otherCount++;
            }
        }
        System.out.println("字母出现次数：" + letterCount);
        System.out.println("空格出现次数：" + spaceCount);
        System.out.println("数字出现次数：" + digitCount);
        System.out.println("其他出现次数：" + otherCount);
    }
}
